# Various yeast related calculations
module Yeast

  # Calculates yeast cells required for fermentation
  #
  # @note
  #     Extract must be measured in Plato, volume in liters
  #
  # @example
  #     Yeast.cells_required({
  #       extract: 15,
  #       volume: 20
  #     })
  #
  #     Yeast.cells_required({
  #       extract: 15,
  #       volume: 20,
  #       type: lager
  #     })
  #
  # @param [Hash] data data required to calculate yeast cells required; `extract`, `volume` and optionally `type`. `type` defaults to `:ale` but may also be `:hybrid` or `:lager`
  # @return [Fixnum] yeast cells required
  def self.cells_required data
    type = data[:type] || :ale

    cells_per_milliliter = case type
    when :ale     then 750_000
    when :hybrid  then 1_125_000
    when :lager   then 1_500_000
    end

    (cells_per_milliliter * (data[:volume] * 1000) * data[:extract]).round
  end

  # Calculates apparent attenuation
  #
  # @note
  #     Extract must be measured in Plato
  #
  # @example
  #     Yeast.attenuation 13.5, 3.1
  #
  # @param [Float] original original Plato
  # @param [Float] current current Plato
  # @return [Fixnum] apparent attenuation
  def self.attenuation original, current
    (((original - current) / original) * 100).round
  end

end
